import { _decorator, Component, director, Node, tween, v2, v3 } from 'cc';
import { AdComponent } from '../AdComponent';
import DatasSpace from '../Tool/DatasSpace';
import { AudioMgr, ENUM_CLIP } from '../Tool/AudioMgr';
const { ccclass, property } = _decorator;

@ccclass('PropShop')
export class PropShop extends Component {

  @property(Node)
  viewNode: Node = null;

  /**
   *  0 是 洗牌道具  
   *  1 是 翻牌道具
   *  2 是 消除道具
   *  3 是 撤回道具
   *  4 是 增加计时道具
   */
  price = [
    300, 300, 300, 300, 300
  ]

  btnClose() {
    AudioMgr.Instance.play(ENUM_CLIP.Click);

    this.btnCloseSetting();
  }

  start() {
    console.log('道具数量', DatasSpace.Instance.propNumArr);
    // AdComponent.Instance.show5X5CustomAd();
    AdComponent.Instance.showInterstitialFullShow();
    // tween(this.viewNode).to(0.3, { position:v3(this.viewNode.getPosition().x,-50,0), scale:v3(1.2,0.8,0)}, { easing: 'smooth' }).to(0.3, { position: v3(0,0,0), scale:v3(1,1,0) }, { easing: 'backInOut' }).to(0.3, { scale:v3(1.1,0.9,0)}, { easing: 'backInOut' }).to(0.1, { scale:v3(1,1,0) }, { easing: 'backInOut' }).call(() => {
    // }).start();
  }

  btnCloseSetting() {
    // AdComponent.Instance.instance.playAudio(2);
    // AdComponent.Instance.hide5X5customAd();
    tween(this.viewNode).to(0.5, { position: v3(0, this.viewNode.getPosition().y + 1600, 0) }, { easing: 'backInOut' }).call(() => {
      this.node.removeFromParent();
      this.node.destroy();

    }).start();
  }

  btnBuyProp(e, cus) {
    AudioMgr.Instance.play(ENUM_CLIP.Click);

    let type = Number(cus);
    if (DatasSpace.Instance.goldNum < this.price[type]) {
      console.log('金币不足');
      return;
    } else {
      DatasSpace.Instance.propNumArr[type] += 1;
      DatasSpace.Instance.goldNum -= this.price[type];
      DatasSpace.Instance.setPropNum();
      DatasSpace.Instance.setGoldNum();
    }

  }

  videoAdGetProp(e, cus) {
    let type = Number(cus);
    AdComponent.Instance.loadVideoAd(0, (res) => {
      if (res) {
        console.log('广告购买成功');
        DatasSpace.Instance.propNumArr[type] += 1;
        DatasSpace.Instance.setPropNum();
      }
    });
  }

  // update(deltaTime: number) {

  // }
}


